package server;

import java.io.IOException;
import java.util.ArrayList;

import communication.Message;
import communication.message.Player;
import communication.server.ClientHandle;
import communication.server.GMHandle;


public class Play {

	private int playId;
	private ArrayList<ClientHandle> players;
	private GMHandle gm;

	public Play(int playersCount, int id, GMHandle gm) {
		players = new ArrayList<ClientHandle>();
		this.gm = gm;
		playId = id;
	}

	public void addPlayer(ClientHandle player) {
		players.add(player);
	}

	public int getPlayId() {
		return playId;
	}
	
	public GMHandle getGM() {
		return gm;
	}

	public ArrayList<Player> getPlayers() {
		ArrayList<Player> pl = new ArrayList<Player>();
		for(ClientHandle player : players) {
			pl.add(new Player(player.getNick()));
		}
		return pl;
	}
	
	public void sendMessageToPlayers(Message msg) throws IOException {
		for(ClientHandle ch : players) {
			ch.sendMessage(msg);
		}
	}
	
}
